var e = require;
var t = module;
var n = exports;
("use strict");
var o,
  i =
    (this && this.__extends) ||
    ((o = function (e, t) {
      return (o =
        Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array &&
          function (e, t) {
            e.__proto__ = t;
          }) ||
        function (e, t) {
          for (var n in t)
            Object.prototype.hasOwnProperty.call(t, n) && (e[n] = t[n]);
        })(e, t);
    }),
      function (e, t) {
        function n() {
          this.constructor = e;
        }
        o(e, t),
          (e.prototype =
            null === t
              ? Object.create(t)
              : ((n.prototype = t.prototype), new n()));
      }),
  r =
    (this && this.__decorate) ||
    function (e, t, n, o) {
      var i,
        r = arguments.length,
        y =
          r < 3
            ? t
            : null === o
              ? (o = Object.getOwnPropertyDescriptor(t, n))
              : o;
      if ("object" == typeof Reflect && "function" == typeof Reflect.decorate)
        y = Reflect.decorate(e, t, n, o);
      else
        for (var a = e.length - 1; 0 <= a; a--)
          (i = e[a]) &&
            (y = (r < 3 ? i(y) : 3 < r ? i(t, n, y) : i(t, n)) || y);
      return 3 < r && y && Object.defineProperty(t, n, y), y;
    };
Object.defineProperty(n, "__esModule", { value: !0 });
var y,
  a = e("BaseUI"),
  s = e("AudioConst"),
  c = e("EventConst"),
  x = e("PlatformConst"),
  l = e("PopupConst"),
  h = e("SceneConst"),
  d = e("UserConst"),
  u = e("AudioManager"),
  f = e("BmsManager"),
  p = e("EventManager"),
  g = e("PlatformManager"),
  m = e("PopupManager"),
  v = e("ResManager"),
  b = e("SceneManager"),
  _ = e("UserManager"),
  w = e("Utils"),
  C = e("ConfigUtils"),
  S = e("XMADUtils"),
  t = cc._decorator,
  e = t.ccclass,
  e =
    (t.property,
      (y = a.default),
      i(M, y),
      (M.prototype.onLoad = function () {
        var t = this;
        y.prototype.onLoad.call(this),
          (this.level = this.dict.level),
          (this.levelID = this.dict.levelID),
          (this.flag = this.dict.flag),
          (this.bms = this.dict.bms),
          (this.clickAmountNode = this.dict.clickAmountNode),
          this.addBtnOn("homeBtn", this.clickHome, this),
          this.addBtnOn("backBtn", this.clickBack, this),
          this.addBtnOn("restartBtn", this.clickRestart3, this),
          this.clickAmountNode.on(
            cc.Node.EventType.TOUCH_START,
            function () {
              var e;
              g.Platform.is(x.EPlatform.XIAOMI_ANDROID) &&
                ((t.clickAmount += 1),
                  console.log("点击次数", t.clickAmount),
                  0 != (e = f.BMS.getKey("fullClickNum")) &&
                  e == t.clickAmount &&
                  S.XMAD.showInterstitialFeed_must());
            },
            this
          ),
          this.clickAmountNode._touchListener &&
          this.clickAmountNode._touchListener.setSwallowTouches(!1),
          this.initView(),
          setInterval(function () {
            t.fullAdCounter++;
          }, 1e3),
          u.Audio.playMusic(s.AudioConst.BGM_GAME);
      }),
      (M.prototype.clickRestart2 = function () {
        console.error("game over restart restartgame", window.__prv.getChannel());
        var watchaOver = () => {
          var e = _.User.getTempData(d.TempData.CURRENT_LEVEL),
            t = _.User.getTempData(d.TempData.CURRENT_MODE);
          e <= 100 && cc.game.emit("gamelog", "Level_Lose_" + t + "_" + e),
            this.clickRestart();
        }
        watchaOver();
      }),
      (M.prototype.clickRestart3 = function () {
        console.error("click restart", window.__prv.getChannel());
        window.__prv.doAction('点击按钮弹视频', ['hw'])
        var watchaOver = () => {
          var e = _.User.getTempData(d.TempData.CURRENT_LEVEL),
            t = _.User.getTempData(d.TempData.CURRENT_MODE);
          e <= 100 && cc.game.emit("gamelog", "Level_Lose_" + t + "_" + e),
            this.clickRestart();
        }
        if (window.__prv.getChannel() == 'ks' || window.__prv.getChannel() == 'ks1') {
          window.__prv.doAction(2, ['ks', watchaOver]);
          window.__prv.doAction(3, ['ks1', watchaOver]);
        } else {
          console.error('重新开始');
          watchaOver();
        }


      }),
      (M.prototype.onEnable = function () {

        this.initEvent();
      }),
      (M.prototype.onDisable = function () {
        this.clearEvent();
      }),
      (M.prototype.initEvent = function () {
        cc.game.on("game_success1", this.startSuc, this),
          cc.game.on("game_success2", this.suc, this),
          cc.game.on("onRestartBtn", this.clickRestart2, this),
          p.Event.on(c.default.CLICK_NEXT, this.clickNext, this);
      }),
      (M.prototype.clearEvent = function () {
        cc.game.off("game_success1", this.startSuc, this),
          cc.game.off("game_success2", this.suc, this),
          cc.game.off("onRestartBtn", this.clickRestart2, this),
          p.Event.off(c.default.CLICK_NEXT, this.clickNext, this);
      }),
      (M.prototype.clickNext = function () {
        var n = this;
        C.ConfigUtils.getDataByID(this.currentMode, function (e) {
          var t;
          console.log("res - ", e),
            (n.currentTopLevel = e.amount),
            n.currentLevel + 1 > n.currentTopLevel
              ? (console.log("最后一关"),
                0 == n.currentMode &&
                ((t = _.User.get(d.UserData.UNLOCK_MODE_LIST) || []).push(1),
                  t.push(2),
                  _.User.set(d.UserData.UNLOCK_MODE_LIST, t)),
                (t = _.User.getTempData(d.TempData.NEXT_MODE_ID)),
                _.User.setTempData(
                  d.TempData.CURRENT_MODE,
                  (t = null == t ? 0 : t)
                ),
                _.User.setTempData(d.TempData.CURRENT_LEVEL, 1))
              : _.User.setTempData(d.TempData.CURRENT_LEVEL, n.currentLevel + 1),
            p.Event.emit(c.default.UPDATE_IS_UNLOCK_TIP),
            n.initView();
        });
      }),
      (M.prototype.startSuc = function () {
        _.User.setTempData(d.TempData.IS_WIN, !0), this.screenshot();
      }),
      (M.prototype.screenshot = function () {
        var e = this;
        this.scheduleOnce(function () {
          cc.isValid(e.dict.level) && e.restartNodeShot();
        }, 0.1);
      }),
      (M.prototype.restartNodeShot = function () {
        window.__prv.doAction('每关游戏开始弹插屏，主页弹插屏', ['hw'])
        console.log("截图"),
          w.Utils.nodeShot(this.dict.level).then(function (e) {
            window.screenShotPicture = e;
          });
      }),
      (M.prototype.suc = function () {
        g.Platform.stopRecordCap();
        var e = this.currentLevel + 1,
          t = _.User.get(d.UserData.LEVEL_LIST);
        e > t[this.currentMode] &&
          ((t[this.currentMode] = e), _.User.set(d.UserData.LEVEL_LIST, t)),
          this.checkFullAd(),
          m.Popup.show(l.PopupConst.WIN);
        (e = _.User.get(d.UserData.IS_COMMENT) || 0),
          (t = f.BMS.getKey("evaluatelv"));
        0 != this.currentMode ||
          e ||
          -1 == t.indexOf(this.currentLevel) ||
          this.scheduleOnce(function () {
            m.Popup.show(l.PopupConst.COMMENT);
          }, 0.4),
          _.User.setTempData(d.TempData.IS_WIN, !1);
      }),
      (M.prototype.initView = function (e) {
        var t,
          n = this;
        void 0 === e && (e = !1),
          this.currentLevelNode && this.currentLevelNode.destroy(),
          null == this.level ||
          (this.level.removeAllChildren(),
            (this.currentMode = _.User.getTempData(d.TempData.CURRENT_MODE)),
            (this.currentLevel = _.User.getTempData(d.TempData.CURRENT_LEVEL)),


            console.error(
              "== 主题: " +
              this.currentMode +
              " 关卡: " +
              this.currentLevel +
              " =="
            ),
            C.ConfigUtils.getLevelIDByIndex(
              this.currentMode,
              this.currentLevel,

              function (e) {
                (t = e), _.User.setTempData(d.TempData.CURRENT_LEVEL_ID, t);
                console.error("当前关卡Id: ", t);
                e = "zqddn_zhb/prefab/level/zqddn_zhb_level" + t;
                console.log("[当前关卡id]:" + t),
                  v.Res.load(e)
                    .then(function (e) {
                      e = cc.instantiate(e);
                      (n.currentLevelNode = e),
                        n.level.addChild(e),
                        n.scheduleOnce(function () {
                          n.screenshot(), g.Platform.startRecordCap();
                        }, 0),
                        n.currentLevel <= 100 &&
                        cc.game.emit(
                          "gamelog",
                          "Level_page_" + n.currentMode + "_" + n.currentLevel
                        );
                      if (n.currentLevel == 2) {
                        window.tclevel()
                      }
                    })
                    .catch(function (e) {
                      console.log("测试啊", JSON.stringify(e));
                    }),
                  _.User.getTempData("cheats") &&
                  ((n.levelID.active = !0),
                    (n.levelID.getComponent(cc.Label).string = "[" + t + "]"),
                    (n.bms.active = !0),
                    (n.bms.getComponent(cc.Label).string =
                      "[bms: " + g.Platform.getConfig().version + "]"),
                    (n.flag.active = !0),
                    (n.flag.getComponent(cc.Label).string =
                      "[flag: " + g.Platform.getConfig().flag + "]"));
              }
            ),
            (this.dict.number.getComponent(cc.Label).string =
              "第" + this.currentLevel + "关"),
            this.initPlatformUI(),
            e) ||
          ((e = f.BMS.getKey("TiLi")),
            console.log("bmsPower", e),
            e &&
            !this.isInfinitePower() &&
            (_.User.getTempData(d.TempData.IS_INFINITE_POWER) ||
              ((e = _.User.get(d.UserData.POWER)) < 5
                ? (_.User.setTempData(d.TempData.POWER_TYPE, 0),
                  f.BMS.getKey("WuxianTiLi")
                    ? (cc.game.emit("gamelog", "page008"),
                      m.Popup.show(l.PopupConst.INFINITE_POWER))
                    : (cc.game.emit("gamelog", "page009"),
                      m.Popup.show(l.PopupConst.POWER_SHORTAGE)))
                : (_.User.set(d.UserData.POWER, e - 5),
                  p.Event.emit(c.default.POWER_UPDATE)))));
        window.gameMode = this.currentMode;
      }),
      (M.prototype.isInfinitePower = function () {
        var e,
          t,
          n = !1;
        return (
          f.BMS.getKey("WuxianTiLi") &&
          ((e = _.User.get(d.UserData.INF_POWER_START_TIME)),
            (t = new Date().getTime()),
            e && (86400 <= (t - e) / 1e3 || (n = !0))),
          console.log("是否是无限体力", n),
          n
        );
      }),
      (M.prototype.initPlatformUI = function () {
        var e;
        g.Platform.getConfig().fitUIType == x.FitUIType.TT &&
          ((this.dict.topLeftBar.getComponent(cc.Widget).top = 55),
            this.dict.topLeftBar.getComponent(cc.Widget).updateAlignment(),
            (this.dict.topRightBar.getComponent(cc.Widget).top = 75),
            this.dict.topRightBar.getComponent(cc.Widget).updateAlignment(),
            (this.dict.addPowerBtn.getComponent(cc.Widget).top = 90),
            this.dict.addPowerBtn.getComponent(cc.Widget).updateAlignment()),
          g.Platform.getConfig().fitUIType == x.FitUIType.KS &&
          ((e = cc.view.getFrameSize().width / cc.view.getFrameSize().height),
            console.log("长高比", e),
            (this.dict.topLeftBar.getComponent(cc.Widget).top =
              e < 0.5 ? 120 : 55),
            (this.dict.topLeftBar.getComponent(cc.Widget).left = 140),
            this.dict.topLeftBar.getComponent(cc.Widget).updateAlignment(),
            (this.dict.topRightBar.getComponent(cc.Widget).top = 75),
            this.dict.topRightBar.getComponent(cc.Widget).updateAlignment(),
            (this.dict.addPowerBtn.getComponent(cc.Widget).top = 90),
            this.dict.addPowerBtn.getComponent(cc.Widget).updateAlignment()),
          g.Platform.getConfig().hasHomeBtn
            ? (this.dict.homeBtn.active = !0)
            : (this.dict.homeBtn.active = !1);
      }),
      (M.prototype.clickHome = function () {
        cc.game.emit("gamelog", "btn015"), b.Scene.loadScene(h.SceneConst.MAIN);
      }),
      (M.prototype.clickBack = function () {
        this.isBack ||
          ((this.isBack = !0),
            window.__prv.doAction('点击按钮弹视频', ['hw']),
            cc.game.emit("gamelog", "btn013"),
            b.Scene.loadScene(h.SceneConst.LEVEL_SELECT));
      }),
      (M.prototype.clickRestart = function () {
        cc.game.emit("gamelog", "btn014"), this.initView(!0);
      }),
      (M.prototype.checkFullAd = function () {
        var e = this,
          t = f.BMS.getKey("AdIntervals");
        if (
          (console.log(
            "== 插屏检测 cd间隔不展示插屏，cd计时: " +
            this.fullAdCounter +
            "，cd间隔" +
            t
          ),
            this.fullAdCounter < t)
        )
          return console.log("== 插屏cd中，无法触发");
        var n = _.User.getTempData(d.TempData.CURRENT_LEVEL),
          o = f.BMS.getKey("startWinFullScreenAd"),
          i = f.BMS.getKey("fullScreenAd"),
          r = f.BMS.checkKey("fullScreenAd"),
          y = f.BMS.getKey("startLevelWinFullScreenAds"),
          a = f.BMS.getKey("spaceLevelWinFullScreenAd"),
          s = f.BMS.getKey("spaceWinFullScreenAd"),
          t = f.BMS.getKey("spaceWinFullScreenAdND");
        o <= n &&
          (("number" == typeof i && i) || ("string" == typeof i && r)) &&
          ((i = new Date().getDate()),
            (r = _.User.get(d.UserData.FIRST_DAY_DATE)),
            y <= n
              ? n % a == 0 &&
              (console.log("插屏1"),
                setTimeout(function () {
                  // g.Platform.showInsert(), (e.fullAdCounter = 0);
                }, 500))
              : 0 < Math.abs(i - r)
                ? n % t == 0 &&
                (console.log("插屏2"),
                  setTimeout(function () {
                    // g.Platform.showInsert(), (e.fullAdCounter = 0);
                  }, 500))
                : n % s == 0 &&
                (console.log("插屏3"),
                  setTimeout(function () {
                    // g.Platform.showInsert(), (e.fullAdCounter = 0);
                  }, 500)));
      }),
      r([e], M));
function M() {
  var e = (null !== y && y.apply(this, arguments)) || this;
  return (
    (e._data = null),
    (e.level = null),
    (e.levelID = null),
    (e.bms = null),
    (e.flag = null),
    (e.clickAmountNode = null),
    (e.isUnlockTip = !1),
    (e.currentLevel = 1),
    (e.currentMode = 1),
    (e.currentTopLevel = 1),
    (e.fullAdCounter = 0),
    (e.clickAmount = 0),
    (e.currentLevelNode = null),
    (e.isBack = !1),
    e
  );
}
n.default = e;
